﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BeanboxSoftware.BeanProxy;

namespace BeanProxyTest
{
  [TestClass]
  public class CtorTest
  {
    [TestMethod]
    public void SimpleCtorTest()
    {
      ManyCtor proxy = ProxyManager.CreateProxy<ManyCtor>();

      Assert.AreEqual(CtorType.Default, proxy.CtorType);
      Assert.IsNull(proxy.Data);

      proxy = ProxyManager.CreateProxy<ManyCtor>(14);

      Assert.AreEqual(CtorType.A, proxy.CtorType);
      Assert.AreEqual(14, proxy.Data);

      proxy = ProxyManager.CreateProxy<ManyCtor>("hello");

      Assert.AreEqual(CtorType.B, proxy.CtorType);
      Assert.AreEqual("hello", proxy.Data);

      proxy = ProxyManager.CreateProxy<ManyCtor>(((object)1.4));

      Assert.AreEqual(CtorType.C, proxy.CtorType);
      Assert.AreEqual(1.4, proxy.Data);

      proxy = ProxyManager.CreateProxy<ManyCtor>(new CtorConfig().Add<string>(null));

      Assert.AreEqual(CtorType.B, proxy.CtorType);
      Assert.IsNull(proxy.Data);

      proxy = ProxyManager.CreateProxy<ManyCtor>(new CtorConfig().Add<Parent>(new Child()));

      Assert.AreEqual(CtorType.D, proxy.CtorType);
      Assert.IsTrue(proxy.Data is Child);

      proxy = ProxyManager.CreateProxy<ManyCtor>(new CtorConfig().Add(new Child()));

      Assert.AreEqual(CtorType.D, proxy.CtorType);
      Assert.IsTrue(proxy.Data is Child);

      proxy = ProxyManager.CreateProxy<ManyCtor>(new Child());

      Assert.AreEqual(CtorType.D, proxy.CtorType);
      Assert.IsTrue(proxy.Data is Child);

      proxy = ProxyManager.CreateProxy<ManyCtor>(new Parent());

      Assert.AreEqual(CtorType.D, proxy.CtorType);
      Assert.IsTrue(proxy.Data is Parent);
    }
  }

  public enum CtorType
  {
    Default,
    A,
    B,
    C,
    D,
  }

  public class ManyCtor
  {
    public CtorType CtorType { get; set; }
    public object Data { get; set; }

    public ManyCtor()
    {
      CtorType = CtorType.Default;
    }

    public ManyCtor(int i)
    {
      CtorType = CtorType.A;
      Data = i;
    }

    public ManyCtor(string s)
    {
      CtorType = CtorType.B;
      Data = s;
    }

    public ManyCtor(object o)
    {
      CtorType = CtorType.C;
      Data = o;
    }

    protected ManyCtor(Parent p)
    {
      CtorType = CtorType.D;
      Data = p;
    }
  }

  public class Parent
  {
  }

  public class Child : Parent
  {
  }
}

/////